﻿<!DOCTYPE html>
<style>
 #btnEditSure{
     color: #fff;
     width:100px;
     height:29px;
    background-color: #00BFFF;
    border:none;
    /*border-color: #00BFFF;*/
    text-shadow: 0 -1px 0 rgba(0,0,0,0.12);
    -webkit-box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    box-shadow: 0 2px 0 rgba(0,0,0,0.045);
    margin-top:20px;
 }
</style>
<div id="main">
    <table  id="tabEditFrm" style="width:auto;height:180px;">
        
    </table>
    <table  style="width:auto;height:29px;border:1px solid red;" >
        <tr>
            <td style="width:300px;border:1px solid black;text-align:center;">合计:</td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td1"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td2"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td3"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td4"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td5"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td6"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td7"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td8"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td9"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td10"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td11"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td12"></td>
            <td style="width:80px;border:1px solid black;text-align:center;" id="td13"></td>
        </tr>
    </table>
</div>
<div id="nav" style="border:1px solid #808080;width:950px;height:230px;text-align:center;">


    用户号: <span id="editID" style="color:#ff6a00;"></span>&nbsp;&nbsp;&nbsp;
    用户名: <span id="editName" style="color:#ff6a00;"></span><br /><br />
    <table id="eidtmain" style="text-align:center;margin:0 auto;">
        <tr>
            <td>一月</td>
            <td><input id="txt1" type="text" onchange="sumAll()" /></td>
            <td>二月</td>
            <td><input id="txt2" type="text" onchange="sumAll()" /></td>
            <td>三月</td>
            <td><input id="txt3" type="text" onchange="sumAll()" /></td>
        </tr>
        <tr>
            <td>四月</td>
            <td><input id="txt4" type="text" onchange="sumAll()" /></td>
            <td>五月</td>
            <td><input id="txt5" type="text" onchange="sumAll()" /></td>
            <td>六月</td>
            <td><input id="txt6" type="text" onchange="sumAll()" /></td>
        </tr>
        <tr>
            <td>七月</td>
            <td><input id="txt7" type="text" onchange="sumAll()" /></td>
            <td>八月</td>
            <td><input id="txt8" type="text" onchange="sumAll()" /></td>
            <td>九月</td>
            <td><input id="txt9" type="text" onchange="sumAll()" /></td>
        </tr>
        <tr>
            <td>十月</td>
            <td><input id="txt10" type="text" onchange="sumAll()" /></td>
            <td>十一月</td>
            <td><input id="txt11" type="text" onchange="sumAll()" /></td>
            <td>十二月</td>
            <td><input id="txt12" type="text" onchange="sumAll()" /></td>
        </tr>
    </table><br />

    全年:<span id="sumAll" style="color:red;"></span></td><br />
    <span id="errorTitle" style="color:red;"></span>
    <input id="btnEditSure" type="button" value="确认修改" />
    
 
</div>
<script>
    $().ready(function () {

        $.ajaxSetup({
            async: false
        });
        var lx = getQueryParam("lx");
        var bh = getQueryParam("bh");
        var params = { lx: lx, bh: bh };
        //初始化加载
        $("#tabEditFrm").datagrid({
            url: "../../../ashx/EditDaiChuLi.ashx?type=show",
            queryParams: params,
            closed: false,
            cache: true,
            showFooter: true,
            rownumbers: false,
            fitColumns: true,
            singleSelect: true,
            onClickRow: onClickRow,
            columns: [[
                 { field: "S_YONGHUH", title: "用户号", width: 80 },
                 { field: "S_YONGHUM", title: "用户名", width: 130 },
                 {
                     field: "IM_1", title: "一月", width: 80
                 },
                 { field: "IM_2", title: "二月", width: 80},
                 { field: "IM_3", title: "三月", width: 80  },
                 { field: "IM_4", title: "四月", width: 80 },
                 { field: "IM_5", title: "五月", width: 80 },
                 { field: "IM_6", title: "六月", width: 80 },
                 { field: "IM_7", title: "七月", width: 80 },
                 { field: "IM_8", title: "八月", width: 80 },
                 { field: "IM_9", title: "九月", width: 80 },
                 { field: "IM_10", title: "十月", width: 80 },
                 { field: "IM_11", title: "十一月", width: 80 },
                 { field: "IM_12", title: "十二月", width: 80 },
                 { field: "IM_13", title: "全年", width: 80 }
            ]]
        });
        sumAllNum();
        //修改
        var rowIndex;
        $("#btnEditSure").click(function () {
            var id = $("#editID").html();
            if (id == "")
            {
                alert("请选择要修改的数据");
                return;
            }
            var laihanbh = getQueryParam("bh");
            var i_m1 = $("#txt1").val();
            var i_m2 = $("#txt2").val();
            var i_m3 = $("#txt3").val();
            var i_m4 = $("#txt4").val();
            var i_m5 = $("#txt5").val();
            var i_m6 = $("#txt6").val();
            var i_m7 = $("#txt7").val();
            var i_m8 = $("#txt8").val();
            var i_m9 = $("#txt9").val();
            var i_m10 = $("#txt10").val();
            var i_m11 = $("#txt11").val();
            var i_m12 = $("#txt12").val();
            $.post("../../../ashx/EditDaiChuLi.ashx",
                    {
                        type: 'Edit',
                        id: id,
                        laihanbh: laihanbh,
                        i_m1: i_m1,
                        i_m2: i_m2,
                        i_m3: i_m3,
                        i_m4: i_m4,
                        i_m5: i_m5,
                        i_m6: i_m6,
                        i_m7: i_m7,
                        i_m8: i_m8,
                        i_m9: i_m9,
                        i_m10: i_m10,
                        i_m11: i_m11,
                        i_m12: i_m12
                    }),
            $("#tabEditFrm").datagrid("reload");
            $("#tabEditFrmMain").datagrid("reload");
            sumAllNum();

            $("#tdmain1").html(compute("IM_1"));
            $("#tdmain2").html(compute("IM_2"));
            $("#tdmain3").html(compute("IM_3"));
            $("#tdmain4").html(compute("IM_4"));
            $("#tdmain5").html(compute("IM_5"));
            $("#tdmain6").html(compute("IM_6"));
            $("#tdmain7").html(compute("IM_7"));
            $("#tdmain8").html(compute("IM_8"));
            $("#tdmain9").html(compute("IM_9"));
            $("#tdmain10").html(compute("IM_10"));
            $("#tdmain11").html(compute("IM_11"));
            $("#tdmain12").html(compute("IM_12"));
            $("#tdmain13").html(compute("IM_13"));
            //$("#UCLHShenPiXX_FH_btnD").click();
            //$("#UCLHShenPiXX_FH_txtLX").css("display", "none");
            //$("#UCLHShenPiXX_FH_txtBH").css("display", "none");
            //$("#UCLHShenPiXX_FH_btnD").css("display", "none");
            //$('#tabEditFrm').datagrid("selectRow", rowIndex);
        });

        //初始化全部列合计
        function sumAllNum() {
            $("#td1").html(compute("IM_1"));
            $("#td2").html(compute("IM_2"));
            $("#td3").html(compute("IM_3"));
            $("#td4").html(compute("IM_4"));
            $("#td5").html(compute("IM_5"));
            $("#td6").html(compute("IM_6"));
            $("#td7").html(compute("IM_7"));
            $("#td8").html(compute("IM_8"));
            $("#td9").html(compute("IM_9"));
            $("#td10").html(compute("IM_10"));
            $("#td11").html(compute("IM_11"));
            $("#td12").html(compute("IM_12"));
            $("#td13").html(compute("IM_13"));
        }
    });
    
    //单击行赋值
    function onClickRow(index) {
        var row = $("#tabEditFrm").datagrid('getSelected');
        $("#editID").html(row.S_YONGHUH);
        $("#editName").html(row.S_YONGHUM);
        $("#txt1").val(row.IM_1);
        $("#txt2").val(row.IM_2);
        $("#txt3").val(row.IM_3);
        $("#txt4").val(row.IM_4);
        $("#txt5") .val( row.IM_5);
        $("#txt6") .val(row.IM_6);
        $("#txt7") .val( row.IM_7);
        $("#txt8") .val( row.IM_8);
        $("#txt9") .val( row.IM_9);
        $("#txt10") .val( row.IM_10);
        $("#txt11") .val( row.IM_11);
        $("#txt12") .val( row.IM_12);
        $("#sumAll").html(row.IM_13);
    }


    function compute(colName){
        var rows = $('#tabEditFrm').datagrid('getRows');
        var total = 0;
        for (var i = 0; i < rows.length; i++) {
            if(rows[i][colName]!=null&&rows[i][colName]!=""){
                total += parseFloat(rows[i][colName]);
            }
        }
        return total;
    }
   



    //全年合计
    function sumAll() {
        var i_m1 = $("#txt1").val();
        var i_m2 = $("#txt2").val();
        var i_m3 = $("#txt3").val();
        var i_m4 = $("#txt4").val();
        var i_m5 = $("#txt5").val();
        var i_m6 = $("#txt6").val();
        var i_m7 = $("#txt7").val();
        var i_m8 = $("#txt8").val();
        var i_m9 = $("#txt9").val();
        var i_m10 = $("#txt10").val();
        var i_m11 = $("#txt11").val();
        var i_m12 = $("#txt12").val();
        var sum = parseInt(i_m1) + parseInt(i_m2) +parseInt( i_m3) + 
            parseInt(i_m4 )+ parseInt(i_m5) +parseInt( i_m6) + 
            parseInt(i_m7) + parseInt(i_m8) + parseInt(i_m9) +
            parseInt(i_m10) + parseInt(i_m11) + parseInt(i_m12);
        $("#sumAll").html(sum);
    }

    //获取页面url参数
    function getQueryParam(name) {
        var obj = $('#frmEdit').dialog("options");
        var queryParams = obj["queryParams"];
        return queryParams[name];
    }
</script>

